package utilz;

import mian.Game;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

public class LoadSave {
    public static final String LEVEL_ATLAS="outside_sprites.png";
    public static final String PLAYER_ATLAS="player_sprites.png";
    public static final String LEVEL_ONE_DATA="level_one_data.png";

    public static BufferedImage GetPlayerAtlas(String filename){
        BufferedImage img=null;
        InputStream inputStream=LoadSave.class.getResourceAsStream("/"+filename);
        try {
              img= ImageIO.read(inputStream);
            } catch (IOException e){
            e.printStackTrace();
        }finally {
            try{
                inputStream.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
       return img;
    }
public static int[][] GetLeveData() {
    int[][] lvlData = new int[Game.TILE_IN_HEIGHT][Game.TILES_IN_WIDTH];
    BufferedImage img = GetPlayerAtlas(LEVEL_ONE_DATA);
    for (int j = 0; j < img.getHeight(); j++) {
        for (int i = 0; i < img.getWidth(); i++) {
            Color color = new Color(img.getRGB(i, j));
            int value = color.getRed();
            if (value >= 48)
                value = 0;
            lvlData[j][i] = value;
        }
    }
    return lvlData;
}
}
